package com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.AdBannerInfo;
import com.hq.fxh.R;
import com.hq.fxh.Utils.GlideUtils;


/**
 * Created by Lenovo on 2016/11/26.
 */
public class TiePianAdContentItem extends LinearLayout {
    /**
     * 贴片广告
     */
    private ImageView pic;
    private TextView show_time;
    private TextView click_effect;
    private TextView time;

    public TiePianAdContentItem(Context context) {
        super(context);
        inflate(context, R.layout.item_tiepian_ad_content, this);
        initView();
    }

    private void initView() {
        pic = (ImageView) findViewById(R.id.pic);
        show_time = (TextView) findViewById(R.id.show_time);
        click_effect = (TextView) findViewById(R.id.click_effect);
        time = (TextView) findViewById(R.id.time);
    }

    /**
     * @param adInfo
     */
    public void showAdInfo(final AdBannerInfo adInfo) {
        if (adInfo != null) {
            final AdBannerInfo.AdvertDetailBean adBean = adInfo.getAdvert_detail();
            if (adBean != null) {
                show_time.setText((adBean.getDuring() != null ? adBean.getDuring() : 3) + "秒广告");
                if (adBean.getAction() != null && adBean.getAction() == 1) {//1跳转链接 2拨打电话
                    click_effect.setText("图片点击效果：跳转链接");
                } else if (adBean.getAction() != null && adBean.getAction() == 2) {
                    click_effect.setText("图片点击效果：拨打电话");
                } else if (adBean.getAction() != null && adBean.getAction() == 3) {
                    click_effect.setText("图片点击效果：联系QQ");
                }
                time.setText("广告显示时间：" + (adBean.getDuring() != null ? adBean.getDuring() : 3) + "秒");
                String url = adBean.getPic();
                if (!TextUtils.isEmpty(url)) {
//                    GlideUtils.loadRoundedImage(getContext(),url,getContext().getResources().getDimensionPixelSize(R.dimen.size_6),pic);
                    GlideUtils.loadImageView(getContext(), url, pic);
                }
            }
        }
    }
}
